<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>系统登录</title>
    <link rel="stylesheet" href="css/login.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/myAjax.js"></script>
    <script type="text/javascript" src="js/pub.js"></script>
    <script src="lib/layui/layui2.5.7.js" charset="utf-8"></script>
</head>

<body class="login-bg">

<div id="app" class="login">
    <div class="message">后台系统登录</div>
    <div id="darkbannerwrap"></div>
    <div class="layui-form">
        <input name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input name="pwd" lay-verify="required" @keyup.enter="login" placeholder="密码" type="password"
               class="layui-input">
        <hr class="hr15">
        <input value="登录" lay-submit lay-filter="login" ref="login" style="width:100%;" type="submit">
        <hr class="hr20">
    </div>
</div>
<script type="text/javascript" src="js/vue.min.js"></script>
<script>

    new Vue({
        el: "#app",
        methods: {
            login() {
                this.$refs.login.click();
            }
        }
    });


    layui.use(['form'],
        function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //监听提交
            form.on('submit(login)',
                function (data) {

                    var request = {
                        url: "user/toLogin",
                        method: "POST",
                        data: data.field
                    };
                    sendRequest(request, (res) => {
                        if (res.code === 0) {
                            localStorage.setItem("token", res.data.token);
                            localStorage.setItem("userId", res.data.userId);
                            localStorage.setItem("roleId", res.data.roleId);
                            localStorage.setItem("nickName", res.data.nickName);
                            localStorage.setItem("headImgUrl", res.data.headImgUrl);
                            localStorage.setItem("roleRoute", JSON.stringify(res.data.menuDTOList));
                            layer.msg("登陆成功,正在跳转...");
                            setTimeout(function () {
                                window.location.href = "index.html";
                            }, 100)
                        } else {
                            layer.msg(res.msg);
                        }

                    });

                    return false;
                });
            return false;
        });

</script>


<!-- 底部结束 -->

</body>

</html>
